﻿/*文件注释
 * ===============================================================================
 * 说明：
 * 作者：曾永佑
 * 版本：V1.0
 * 创建日期：2013-03-03
 * 完成日期： 
 * 修改纪录：  
 * ===============================================================================
 */  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SRF.Security.Permission;
using SRF.Security.Principal;

namespace SRF.Components.Security
{
    public class MyPermissionProvider : SRF.Security.Permission.PermissionProvider
    {
        readonly Data.DBHelperBase dbhelper = Data.DBHelperFactory.GetDBHelper();

        public override IEnumerable<UIPermission> GetUIPermissions(IUser user)
        {
            return dbhelper.GetQuery(Constants.GetPermissionListSQL)
                .SetParameter(new { UserId = user.Id })
                .List<UIPermission>().Where(m => !string.IsNullOrEmpty(m.Code));
        }

        public override IEnumerable<UrlPermission> GetUrlPermissions(IUser user)
        {
            return dbhelper.GetQuery(Constants.GetPermissionListSQL)
                .SetParameter(new { UserId = user.Id })
                .List<UrlPermission>().Where(m => !string.IsNullOrEmpty(m.Url));
        }

        public override IEnumerable<UrlPermission> GetAllUrlPermissions()
        {
            return dbhelper.GetQuery(Constants.GetPermissionListSQL)
                .List<UrlPermission>().Where(m => !string.IsNullOrEmpty(m.Url));
        }

        public override IEnumerable<UrlPermission> GetActUrlPermissions()
        {
            return dbhelper.GetQuery(Constants.GetActUrlPermissionListSQL)
                .List<UrlPermission>();
        }
    }
}